#include "set_timer.h"


void myTimerInit(void)
{
	TCD0.PER = 65535;	//Set Periode Max
}

void myTimerEventInit(void)
{
	TCD0.PER = 16000;	//Set Periode 0.5 detik
	EVSYS.CH7MUX = EVSYS_CHMUX_TCD0_OVF_gc; //Konfigurasi TimerD Channel 0 Overvlow event sebagai even generator di CH7 Event System
}

void myTimerStart(void)
{
	TCD0.CTRLA = TC_CLKSEL_DIV1024_gc; // ftimer  = 32MHz (fPER) / 1024 = 32KHz
}

int myTimerStop(void)
{
	int temp;
	
	TCD0.CTRLA = TC_CLKSEL_OFF_gc; // Stop Timer
	temp = TCD0.CNT;
	TCD0.CNT = 0x0000;
	
	return temp;
}